{% extends "base.html" %}
{% block msgbar %}
<div id="id_edit_tip" class="hidden col-md-12">
    <div class="alert alert-warning alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span></button>
        <strong>您已进入编辑模式！</strong>
        <p>双击书籍标题（或其他标红字段），即可编辑；编辑完毕后会自动保存。</p>
    </div>
</div>
{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-12">
        <div class="center-block">
            <legend><h2 class="text-center book-edit" data-meta="title">{{book.title}}</h2></legend>
        </div>

        <div class="media">
            <div class="col-sm-5 col-md-5 center-block">
            <img class="media-object" style="max-width: 99%"  src="{{IMG}}/get/thumb_300_420/{{book.id}}.jpg?t={{book.timestamp}}" alt="...">
            </div>
            <div class="media-body">
                <p class="lead">

                <span class="field-name">作者：</span>
                <span class="hidden book-edit" data-meta="authors">{{book.author_sort}}</span>
                <a id="id_authors" class="meta-link" href="/author/{{book.author_sort|urlencode}}">{{book.author_sort}}</a><br/>

                {% if book.publisher %}
                <span class="field-name">出版：</span>
                <span class="hidden book-edit" data-meta="publisher">{{book.publisher}}</span>
                <a id="id_publisher" class="meta-link" href="/pub/{{book.publisher|urlencode}}">{{book.publisher}}</a><br/>
                {% endif %}

                {% if book.series %}
                <span class="field-name">系列：</span>
                <span class="book-edit" data-meta="series">{{book.series}}</span><br/>
                {% endif %}

                {% if book.pubdate %}
                <span class="field-name">日期：</span>
                <span >{{book.pubdate|day}}</span><br/>
                {% endif %}

                {% if book.timestamp %}
                <span class="field-name">整理：</span>
                <span >{% if book.collector %}{{book.collector.username}}{% endif %}, {{book.timestamp|day}}</span><br/>
                {% endif %}

                {% if book.language %}
                <span class="field-name">语言：</span>
                <span class="book-edit" data-meta="language">{{book.language}}</span><br/>
                {% endif %}

                <span class="field-name">ISBN： </span>
                <span class="book-edit" data-meta="isbn">
                {% if book.isbn %} {{book.isbn}} {% else %} 暂无 {% endif %}
                </span><br/>

                <span class="field-name">链接：</span>
                {% if book.website %}
                <span >{{book.website|website|safe}}</span><br/>
                {% elif book.isbn %}
                <span ><a target="_blank" href="https://book.douban.com/isbn/{{book.isbn}}/">豆瓣</a></span><br/>
                {% else %}
                暂无<br/>
                {% endif %}

                <span class="field-name">热度：</span>
                <span >{{book.count_visit}} 分</span><br/>

                <span class="field-name">下载：</span>
                <span >{{book.count_download}} 次</span><br/>

                <span class="field-name">评分：</span>
                {% if book.rating %} {{book.rating}} 分 {% else %} 暂无评分 {% endif %}
                <span style="display: inline-block;font-size:65%"><input type="number" class="rating"
                    onchange="update_rating(this, {{book.id}})"
                    value="{%if book.rating%}{{book.rating}}{%endif%}"
                    data-min=0 data-max=10 data-size="xs" ></span><br/>

                {% if book.tags %}
                <span class="field-name">标签：</span>
                <span class="hidden book-edit" data-meta="tags">{{book.tags|join(" / ")}}</span>
                <span id="id_tags" class="meta-link">
                {% for tag in book.tags %}
                <a href="/tag/{{tag|urlencode}}">{{tag}}</a>
                {% if not loop.last %} / {% endif %}
                {% endfor%}
                </span>
                <br/>
                {% endif %}

                </p>
            </div>
        </div>
        <p>&nbsp;</p>

        <span class="legend">简介</span>
        {% if book.comments %}
        <p id="book-comments" class="book-edit" style="text-indent:2em;" data-meta="comments">{{book.comments|replace("\n", "<br/>")}}</p>
        {% else %}
        <p id="book-comments" class="book-edit" style="text-indent:2em;" data-meta="comments">暂无简介</p>
        {% endif %}
        <p>&nbsp;</p>
    </div>
</div>
{% endblock %}

{% block sidebar %}
{% if book.is_public %}
<div class="col-md-12">
    <span class="legend">推送</span>
    <div class="list-group">
        {% if request.user %}
        <a href="#" class="list-group-item" onclick="return jQuery('#id_push_dialog').modal()"><span class="glyphicon glyphicon-phone"></span> Kindle</a>
        {% else %}
        <a href="/login" class="list-group-item" ><span class="glyphicon glyphicon-phone"></span> Kindle</a>
        {% endif %}
    </div>

    <span class="legend">阅读</span>
    <div class="list-group">
        <a class="list-group-item" rel="nofollow" target="_blank" href="/book/{{book.id}}/read"><span class="glyphicon glyphicon-book"></span> 在线阅读</a>
        {% for format, size in sizes %}
        <a rel="nofollow" href="/book/{{book.id}}.{{format}}" class="list-group-item"><span class="glyphicon glyphicon-save"></span> <span class="badge">{{size//1024}} KB</span> {{format}}</a>
        {% endfor %}
    </div>

    {% if book.is_owner %}
    <span class="legend">编辑</span>
    <div class="list-group">
        <a href="#" class="list-group-item" onclick="return book_choose_refer({{book.id}});"><span class="glyphicon glyphicon-refresh"></span> <span class="badge">Douban</span> 更新书籍信息</a>
        {% if request.user.admin %}
        <a href="#" onclick="return bind_book_editable({{book.id}})" class="list-group-item"><span class="glyphicon glyphicon-cog"></span> 手动编辑</a>
        {% endif %}
    </div>

    <span class="legend">管理</span>
    <div class="list-group">
        <a rel="nofollow" href="/book/{{book.id}}/delete" class="btn btn-danger btn-block"><span class="glyphicon glyphicon-remove"></span> 删除</a>
    </div>
    {% endif %}
</div>
{% else %}
<div class="col-md-12">
    <span class="legend">推送</span>
    <div class="alert alert-warning text-center" role="alert">
        应本书版权方要求，该书籍已下架。
    </div>
{% endif %}
{% endblock %}


{% block content_footer %}
<!-- CHANGYAN COMMENT BEGIN -->
<!--
<div id="SOHUCS" sid="{{book.id}}" ></div>
<style>#SOHUCS #SOHU_MAIN .module-mobile-cmt-header { background-color: inherit; } </style>
<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="//changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=cytBSrHjj&conf=prod_8d13f02a29950a434ddf28fd051b732f"></script>
-->
<!-- CHANGYAN COMMENT END -->
{% endblock %}

{% block footer %}
<!-- Modal -->
<div class="modal fade" id="id_push_dialog" tabindex="-1" role="dialog" aria-labelledby="id_push_dialogLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="id_push_dialogLabel">推送Kindle</h4>
            </div>
            <form onsubmit="save_email()" class="form-horizontal" role="form" action="/book/{{book.id}}/push" method="POST">
                <div class="modal-body ">
                    <div class="form-group">
                        <p class="col-sm-12 text-center help-block">&nbsp;</p>
                        <label for="id_push_email" class="col-sm-2 control-label">Email</label>
                        <div class="col-sm-9">
                            <input type="email" class="form-control" name="mail_to" id="id_push_email" value="{{request.user_extra.kindle_email}}" placeholder="Enter email">
                        </div>
                        <p class="col-sm-12 text-center help-block">
                        <br/>请将本站的发件人地址加入Kindle的电子邮箱列表：<strong>{{smtp_username}}</strong></strong> 
                        </p>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Push</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="id_update_dialog" tabindex="-1" role="dialog" aria-labelledby="id_update_dialogLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">从互联网同步书籍信息</h4>
            </div>
            <div class="modal-body" id='id_update_dialog_body'>
                <p>正在搜索...</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block meta %}
<meta name="Keywords" content="{{ title }} {% for format, size in sizes %}{{ format }} {% endfor %} 下载 推送 kindle" />
{% if book.comments %}
<meta name="description" content=" {{ book.comments|striptags|replace("\n", "")|replace('\"', '') }}" />
{% endif %}
{% endblock %}

{% block script %}
<script>
jQuery(document).ready( load_email );
</script>
{% endblock %}

